from node.Node import Node

class LeafSwitch(Node):
    def __init__(self,name,cache_number):
        super().__init__(name,cache_number)
        self.hash_algorithm=None

    def set_hash_algorithm(self,hash_algorithm):
        self.hash_algorithm=hash_algorithm

    def set(self,key,value):
        """
        调用Hash算法找到对应的服务器，得到服务器的名称name，将key,name写入到脊交换机的缓存中
        :param key:
        :param value:
        :return:
        """
        node=self.hash_algorithm.set(key,value)
        super().set(key,node.name)
        return node

    def get(self,key):
        """
        调用Hash算法找到对应的服务器，如果没有在缓存中找到，返回Node
        :param key:
        :return:
        """
        node,value=self.hash_algorithm.get(key)
        return node,value